package com.atguigu.gmall;

import com.atguigu.gmall.common.constant.RedisConst;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * @author: atguigu
 * @create: 2022-11-27 23:04
 */
@SpringBootApplication
@EnableDiscoveryClient
public class ProductApp implements CommandLineRunner {
    //  redisson 这个框架已经帮我们整合好了布隆过滤器。
    @Autowired
    private RedissonClient redissonClient;

    public static void main(String[] args) {
        SpringApplication.run(ProductApp.class, args);
    }

    //  启动的时候，就会执行run方法，初始化布隆过滤器，设置布隆过滤器的数据规模，以及误判率.
    @Override
    public void run(String... args) throws Exception {
        //  初始化布隆过滤器
        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter(RedisConst.SKU_BLOOM_FILTER);
        bloomFilter.tryInit(500000,0.0001);

    }
}